//! 种子收获表

use std::collections::HashMap;

use bevy::ecs::resource::Resource;
///种子收获物品item
#[derive(Clone)]
pub struct SeedHarvestGoodsItems {
    ///收获后物品id
    pub goods_id: u32,
    ///收获后物品数量
    pub goods_num: u32,
}

/// 种子收获配置
#[derive(Clone)]
pub struct SeedHarvestItem {
    ///种子id
    pub seed_id: u32,
    ///收获后物品id
    pub goods_list: Vec<SeedHarvestGoodsItems>,
}

#[derive(Resource)]
pub struct SeedHarvestConfig {
    ///种子收获配置
    pub seed_harvest_list: HashMap<u32, SeedHarvestItem>,
}

impl SeedHarvestConfig {
    fn new() -> Self {
        SeedHarvestConfig {
            seed_harvest_list: HashMap::new(),
        }
    }

    fn add(&mut self, item: SeedHarvestItem) -> &mut Self {
        self.seed_harvest_list.insert(item.seed_id, item.clone());
        self
    }

    ///获取种子收获配置
    pub fn get_seed_harvest(&self, seed_id: u32) -> Option<&SeedHarvestItem> {
        self.seed_harvest_list.get(&seed_id)
    }

    // pub fn get_all_config() -> SeedHarvestConfig {
    //     get_seed_harvest_config()
    // }
}

pub fn get_seed_harvest_config() -> SeedHarvestConfig {
    let mut seed_harvest_config = SeedHarvestConfig::new();
    seed_harvest_config
        .add(SeedHarvestItem {
            seed_id: 0,
            goods_list: vec![
                SeedHarvestGoodsItems {
                    goods_id: 0,
                    goods_num: 2,
                },
                SeedHarvestGoodsItems {
                    goods_id: 2,
                    goods_num: 4,
                },
            ],
        })
        .add(SeedHarvestItem {
            seed_id: 1,
            goods_list: vec![
                SeedHarvestGoodsItems {
                    goods_id: 1,
                    goods_num: 2,
                },
                SeedHarvestGoodsItems {
                    goods_id: 3,
                    goods_num: 4,
                },
            ],
        });
    seed_harvest_config
}
